package com.ruoyi.api.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SpSaicheng;
import com.ruoyi.system.service.ISpSaichengService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 赛程Controller
 * 
 * @author ruoyi
 * @date 2022-11-10
 */
@RestController
@RequestMapping("/api/saicheng")
public class SpSaichengApiController extends BaseController
{
    @Autowired
    private ISpSaichengService spSaichengService;

    /**
     * 查询赛程列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SpSaicheng spSaicheng)
    {
        startPage();
        List<SpSaicheng> list = spSaichengService.selectSpSaichengListWeb(spSaicheng);
        return getDataTable(list);
    }

    /**
     * 导出赛程列表
     */
    @Log(title = "赛程", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SpSaicheng spSaicheng)
    {
        List<SpSaicheng> list = spSaichengService.selectSpSaichengListWeb(spSaicheng);
        ExcelUtil<SpSaicheng> util = new ExcelUtil<SpSaicheng>(SpSaicheng.class);
        util.exportExcel(response, list, "赛程数据");
    }

    /**
     * 获取赛程详细信息
     */
    @GetMapping(value = "/{scId}")
    public AjaxResult getInfo(@PathVariable("scId") Long scId)
    {
        SpSaicheng sc = spSaichengService.selectSpSaichengByScId(scId);
        System.out.println("######:"+sc.getGcDetail());
        return AjaxResult.success(sc);
    }

    /**
     * 新增赛程
     */
    @Log(title = "赛程", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SpSaicheng spSaicheng)
    {
        return toAjax(spSaichengService.insertSpSaicheng(spSaicheng));
    }

    /**
     * 修改赛程
     */
    @Log(title = "赛程", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SpSaicheng spSaicheng)
    {
        return toAjax(spSaichengService.updateSpSaicheng(spSaicheng));
    }

    /**
     * 删除赛程
     */
    @Log(title = "赛程", businessType = BusinessType.DELETE)
	@DeleteMapping("/{scIds}")
    public AjaxResult remove(@PathVariable Long[] scIds)
    {
        return toAjax(spSaichengService.deleteSpSaichengByScIds(scIds));
    }
}
